<%layout("/common/_layout.html"){%>
<%#ajax userTable:{%>
<div class="am-cf am-padding" style="padding:1rem 1.6rem 1.6rem 1rem;margin:0px;">
  <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
  <div class="am-fl am-cf"> <strong class="am-text-primary am-text-lg">角色管理</strong>
    /
    <small>角色列表</small>
  </div>
</div>
<form class="am-form" id="list-form" action="${base}/role/list" method="post">
  <input type="hidden" id="keywords" name="keywords" value='${keywords!""}' />
  <div class="am-g">
    <div class="am-u-sm-12 am-u-md-6" style="padding:0px 1.6rem 1.6rem 1rem;margin:0px;">
      <div class="am-btn-toolbar">
        <div class="am-btn-group am-btn-group-xs" >
          <%if(so.hasPermission("ROLE_CREATE")) {%>
          <button type="button" class="am-btn am-btn-default" onclick="location.href='${base}/role/create'">
            <span class="am-icon-plus"></span>
            新增
          </button>
          <%}%>
          <%if(so.hasPermission("ROLE_DELETE")) {%>
          <button type="button" id="deleteButton" disabled="disabled" class="am-btn am-btn-default" onclick="deleteAll('${base}/role/delete')">
            <span class="am-icon-trash-o"></span>
            删除
          </button>
          <%}%></div>
      </div>
    </div>
    <div class="am-u-sm-12 am-u-md-3" >
      <div class="am-input-group am-input-group-sm">
        <input type="text" class="am-form-field" id="name" value="${name!}" placeholder="按角色名称搜索"/>
        <span class="am-input-group-btn">
          <button id="searchButton" class="am-btn am-btn-default" type="button">搜索</button>
        </span>
      </div>
    </div>
  </div>
</form>
  <div class="am-g" >
    <div class="am-u-sm-12 am-scrollable-horizontal">
      <!--  padding:1px 2px 3px 4px;上、右、下,和左   -->
      <table class="am-table am-table-striped am-table-hover table-main">
        <thead>
          <tr class="am-text-nowrap">
            <th class="table-check">
              <input type="checkbox" id="allCheck"></th>
            <th class="table-id">序号</th>
            <th class="table-title">角色名称</th>
            <th class="table-title">类型</th>
            <th class="table-title">描述</th>
            <th class="table-title">等级</th>
            <th class="table-title">是否启用</th>
            <th class="table-date">创建日期</th>
            <th class="table-date">最后更新日期</th>
            <th class="table-set am-text-center">操作</th>
          </tr>
        </thead>
        <tbody>
          <%for(list in pager.list!){%>
          <tr>
            <td>
              <input type="checkbox" <%if (list.type <= 2){%>
              disabled title="系统内置权限不允许删除!"
              <%}else{%>
              name="ids" value="${list.id}"
              <%}%>/></td>
            <td>${listLP.index}</td>
            <td>${list.name}</td>
            <td>
              <%if (list.type <= 2){%>              
                企业管理员
            <%}else if(list.type==50){%>
              供应商管理员
            <%}else if(list.type==51){%>
              政企管理员
            <%}else{%>
              普通管理员
          <%}%></td>
        <td>${list.description}</td>
        <td>
          <% if(list.level == 1){%>
          省级
          <%}else if(list.level == 2){%>
          地市级
          <%}else if(list.level == 3){%>
          区县级
          <%}else if(list.level == 4){%>
          网点级
          <%}%></td>
        <td>
          <% if(list.is_active){%>
          是
          <%} else {%>
          否
          <%}%>
          <td>${list.created_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
          <td>${list.last_updated_time,dateFormat="yyyy-MM-dd HH:mm:ss"}</td>
          <td>
            <div class="am-btn-toolbar">
              <div class="am-btn-group am-btn-group-xs">
                <%if(so.hasPermission("ROLE_EDIT")) {%>
                <button type="button" class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="location.href='${base}/role/edit?id=${list.id}'">
                  <span class="am-icon-pencil-square-o"></span>
                  编辑
                </button>
                <%}%></div>
            </div>
          </td>
        </tr>
        <%}%></tbody>
    </table>

    <div class="am-cf">
      <!-- 分页 -->
      <%if (pager.list.~size >
      0){%>
      <div class="am-fr">
        <% include("/admin/common_pager.tpl"){}%></div>
      <%}else{%>
      <div class="am-kai">
        <h3>没有找到任何记录!</h3>
      </div>
      <%}%></div>
    <%}%></div>
</div>
<script type="text/javascript">
  var urlBase = "${base}";
  var url;

  $(function(){
      var keywordsObj = {};
      $("#searchButton").on("click",function(){
          if($("#name").val()){
            keywordsObj.name = $("#name").val();
          }
          var keywords = "";
          if(!$.isEmptyObject(keywordsObj)){
            keywords = JSON.stringify(keywordsObj);
          }
          console.log("keywords = "+ keywords);
          $("#keywords").val(keywords);
          showWaitingHint("正在查询，请稍候...");
          $("#list-form").submit();
    });
  });
</script>
<%}%>